package com.carboy.launch.receiver;

import android.app.ActivityManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.carboy.launch.BaseApplication;
import com.carboy.launch.activity.setting.SettingMainActivity;
import com.carboy.launch.utils.AppManager;
import com.carboy.launch.utils.Constants;

/***
 * @author James
 * @Package com.huixin.carnav.receiver
 * @Title: CommonBroadCast.java
 * @Description 通用广播类
 * @date 2015-10-27
 * @version 1.0
 * 
 */
public class CommonBroadCast extends BroadcastReceiver {
	private static final String TAG = "LauncherCar2_CommonBroadCast";
	@Override
	public void onReceive(Context context, Intent intent) {

		String action = intent.getAction();
		// 关闭设置
		if (action.equals(Constants.ACTION_CLOSE_SETTING)) {
			AppManager.getInstance().killActivity(SettingMainActivity.class);
		} else if (action.equals(Constants.ACTION_OPEN_SETTING)) {  //打开设置
			Intent mIntent = new Intent(context, SettingMainActivity.class);
			mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			context.startActivity(mIntent);
		} else if (action.equals(Constants.ACTION_SCREEN_ON)) {  // 语音唤醒亮屏
//			PowerManager mPowerManager = (PowerManager) context
//					.getSystemService(Context.POWER_SERVICE);
//			mPowerManager.setBacklightBrightnessOff(false);
		} else if(action.equals(Constants.ACTION_CLOSE_APP)) {
			String packageName = intent.getStringExtra("kill_package_name");
			Log.v(TAG, "require close " + packageName);
			ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
			try {
				activityManager.forceStopPackage(packageName);
			} catch(Exception e) {
				Log.e(TAG, "close " + packageName + " error");
				e.printStackTrace();
			}
		} else if(action.equals(Constants.ACTION_ACC_OVER_CALLBACK)) {
			BaseApplication.getInstance().standy();
		}
	}
}
